package cn.flying.cloud.tool.code.entity;

import java.io.Serializable;
import java.util.List;

import cn.flying.cloud.base.common.annotation.Column;
import cn.flying.cloud.base.common.utils.lang.StringUtil;

/**
 * @author: admin
 * @date: 2024年07月01日 16:15
 * @version: 1.0
 */
public class Table implements Serializable {

    /**
     * 表名
     */
    @Column(value = "table_name")
    private String name;
    /**
     * 注释
     */
    @Column(value = "table_comment")
    private String comment;
    /**
     * 前缀
     */
    private String prefix;
    /**
     * 类名
     */
    private String clazz;
    /**
     * 属性名首字母小写
     */
    private String capitalName;

    private List<Field> fields;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public String getPrefix() {
        return prefix;
    }

    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }

    public String getClazz() {
        if (StringUtil.isBlank(this.prefix)) {
            return StringUtil.underlineToHeadUpper(this.name);
        }
        return StringUtil.underlineToHeadUpper(this.name.replace(this.prefix, ""));
    }

    public void setClazz(String clazz) {
        this.clazz = clazz;
    }

    public String getCapitalName() {
        if (StringUtil.isBlank(this.prefix)) {
            return StringUtil.underlineToHump(this.name);
        }
        return StringUtil.underlineToHump(this.name.replace(this.prefix, ""));
    }

    public void setCapitalName(String capitalName) {
        this.capitalName = capitalName;
    }

    public List<Field> getFields() {
        return fields;
    }

    public void setFields(List<Field> fields) {
        this.fields = fields;
    }

    @Override
    public String toString() {
        return "Table{" +
                "name='" + name + '\'' +
                ", comment='" + comment + '\'' +
                ", prefix='" + prefix + '\'' +
                ", clazz='" + this.getClazz() + '\'' +
                ", capitalName='" + this.getCapitalName() + '\'' +
                '}';
    }
}
